package leetCode.thread.leetCode1114;

import java.util.concurrent.CountDownLatch;

/**
 * 计数器实现线程协作
 */
public class Foo4 implements Foo {

   CountDownLatch count1 = new CountDownLatch(1);
   CountDownLatch count2 = new CountDownLatch(1);


    @Override
    public void first(Runnable printFirst) throws InterruptedException {
        printFirst.run();
        count1.countDown();
    }

    @Override
    public void second(Runnable printSecond) throws InterruptedException {
        count1.await();
        printSecond.run();
        count2.countDown();
    }

    @Override
    public void third(Runnable printThird) throws InterruptedException {
        count2.await();
        printThird.run();
    }

}
